package com.bblocks.dbmonitor.config;

import com.bblocks.dbmonitor.handler.DefaultCanalEntryHandler;
import com.bblocks.dbmonitor.handler.impl.RecordChangedEvictCacheHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cache.CacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import top.javatool.canal.client.client.CanalClient;

/**
 * <p>Project: bblocks-pro - MonitorConfig</p>
 * <p>描述：监控配置
 * 1、启动通用db变更处理器（新的自行添加）
 * 2、收集器（收集通用处理、收集注解（MonitorTable）标记服务）
 * </p>
 *
 * @Author Zhao [125043150@qq.com]
 * @Date 2024/1/16 11:36
 * @Version 1.0
 * @since 8
 */
@Slf4j
@ConditionalOnClass({ CacheManager.class,CanalClient.class})
public class MonitorConfig {

    /**
     * 自定义处理器（缓存）
     * @param cacheManager
     * @return
     */
    @Bean
    public RecordChangedEvictCacheHandler recordChangedEvictCacheHandler(CacheManager cacheManager){
        log.info("CacheManager:{}",cacheManager);
        return new RecordChangedEvictCacheHandler(cacheManager);
    }



    /**
     * MonitorTable 服务收集
     * @param applicationContext
     * @return
     */
    @Bean
    public  MonitorTableManager annotationMethodManager(ApplicationContext applicationContext) {
        return new MonitorTableManager(applicationContext);
    }

}
